﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BrnMall.Manager.Domain.Store;


namespace BrnMall.Manager.Manager.Store
{
    /// <summary>
    /// 店铺配置
    /// </summary>
    public static class StoreConfigManager
    {
        /// <summary>
        /// 获取店铺积分设置
        /// </summary>
        /// <param name="storeId"></param>
        /// <returns></returns>
        public static CreditConfigInfo GetStoreCreditConfigInfo(int storeId)
        {
            CreditConfigInfo config;
                using (var db = new QDMallDatabase())
            {
                config= db.SingleOrDefault<CreditConfigInfo>($"select top 1 * from bma_CreditConfig where storeid={storeId}");
                if (config != null) return config;
            }
            config = new CreditConfigInfo { StoreId = storeId };
            AddStoreCreditConfigInfo(config);
            return config;
        }
        /// <summary>
        /// 添加配置
        /// </summary>
        /// <param name="con"></param>
        public static void AddStoreCreditConfigInfo(CreditConfigInfo con)
        {
            using (var db = new QDMallDatabase())
            {
                db.Insert(con);
            }
        }
        /// <summary>
        /// 更新店铺积分设置
        /// </summary>
        /// <param name="con"></param>
        public static void UpdateStoreCreditConfigInfo(CreditConfigInfo con)
        {
            using (var db = new QDMallDatabase())
            {
                db.Update(con);
            }
        }
    }
}
